package database;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

import messages.*;

import sharedspace.*;

public class SendFileToClient {
	private String path;
	
	public SendFileToClient(String path)
	{
		this.path = path;
	}
	 public  MyFile sendFileToClient()
	 { 
		 
		try {
			
	 		File newFile = new File(path);
	 		MyFile myFile = new MyFile(newFile.getName());
	 		byte[] mybytearray = new byte [(int)newFile.length()];
	 		FileInputStream fis;
			fis = new FileInputStream(newFile);
			BufferedInputStream bis = new BufferedInputStream(fis);	
		    myFile.initArray(mybytearray.length);
		    myFile.setSize(mybytearray.length);
		    bis.read(myFile.getMybytearray(),0,mybytearray.length);
		    return myFile; 
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		catch(IOException e)
		{
			e.printStackTrace();
		}
		  return null;
	 } 

}
